#  Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#  Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
#  Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
#  Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
#  Vestibulum commodo. Ut rhoncus gravida arcu.

import importlib.util
import logging
import subprocess
import sys
import numpy as np


# 优化算法
def optimized_algorithm(array):
    return np.sum(array)  # 使用NumPy进行快速求和


# 使用装饰器来缓存结果
def memoize(func):
    cache = {}

    def memoized_func(*args):
        if args not in cache:
            cache[args] = func(*args)
        return cache[args]

    return memoized_func


# 使用多线程
from concurrent.futures import ThreadPoolExecutor


def run_concurrently(functions, args):
    with ThreadPoolExecutor() as executor:
        results = list(executor.map(lambda f: f(*args), functions))
    return results
# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

libs = ['numpy', 'pandas', 'pygame', 'pyttsx3', 'kali']

def is_installed(package):
    return importlib.util.find_spec(package) is not None

def install(package):
    if is_installed(package):
        logging.info(f'{package} 已经安装')
        return
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install", package])
        logging.info(f'{package} 安装成功')
    except subprocess.CalledProcessError as e:
        logging.error(f'{package} 安装失败: {e}')

if __name__ == "__main__":
    for lib in libs:
        install(lib)
    logging.info('所有包安装完成')
